<?php

namespace App\Http\Service;

use App\Libs\HttpCurlLibrary;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;

class SmsService extends BaseService
{
    /**
     * 发送短信
     * 
     */   
    public function sms($data)
    {
        $domain=config('request.domain');
        $sms_api=config('request.sms_api');
        $domain_sms_api=$domain.$sms_api;
        //dd($domain_sms_api);
        $res = HttpCurlLibrary::request($domain_sms_api, $data);
        Log::info('发送短信：'.$res);
        $res = json_decode($res, true);
        //dd($res);
        if(isset($res['code']) && $res['code'] == 200){
            $this->success('发送成功');
        }else{
            $this->error('发送失败');
        }
    }

    /**
     * 验证码验证
     */
    public function captchValidate($data)
    {
        if($data['telephone']){
            $data['mobile'] = $data['telephone'];
        }
        $domain=config('request.domain');
        $sms_check_api=config('request.sms_check_api');
        $domain_sms_check_api=$domain.$sms_check_api;
        $is_check=config('request.is_check');
        if($is_check){
            $res = HttpCurlLibrary::request($domain_sms_check_api, $data);
            Log::info('发送短信验证码：'.$res);
            $res = json_decode($res, true);
            if(isset($res['code']) && $res['code'] == 200){
                return true;
            }else{
                return false;
            }
        }else{
            return true;
        }
       
    }

}
